package com.wxzz.elearing.user.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wxzz.elearing.user.dto.MyCheckEnterpriseImproveDto;
import com.wxzz.elearing.user.entity.EnterpriseImprove;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 企业改善 Mapper 接口
 * </p>
 *
 * @author
 * @since 2021-05-17
 */
public interface EnterpriseImproveMapper extends BaseMapper<EnterpriseImprove> {


    List<EnterpriseImprove> listMyCheckEnterpriseImprove(@Param("wxUserId") Long wxUserId, @Param("myCheckEnterpriseImproveDto") MyCheckEnterpriseImproveDto myCheckEnterpriseImproveDto);


    /**
     * 改善之星
     *
     * @param enterpriseId
     * @param startTime
     * @param endTime
     * @return
     */
    List<EnterpriseImprove> selectSumByEnterpriseImprove(@Param("enterpriseId") Long enterpriseId, @Param("startTime") String startTime, @Param("endTime") String endTime);

    /**
     * SELECT
     * wx_user_id,
     * SUM( 1 ) improveNum
     * FROM
     * `enterprise_improve`
     * WHERE
     * enterprise_id = 1397458468151992321
     * AND STATUS = 1
     * AND create_time BETWEEN '1111-12-22'
     * AND '2222-12-22'
     * GROUP BY
     * wx_user_id
     * ORDER BY
     * SUM( 1 ) DESC
     */

    @Select("SELECT\n" +
            "\tCOUNT( 1 ) \n" +
            "FROM\n" +
            "\tenterprise_improve \n" +
            "WHERE\n" +
            "\tenterprise_id = #{enterpriseId} \n" +
            "\tAND STATUS = 1 \n" +
            "\tAND deleted = 0 \n" +
            "\tAND create_time BETWEEN #{startTime} \n" +
            "\tAND #{endTime}")
    Integer selectEnterpriseImproveVo(@Param("enterpriseId") Long enterpriseId, @Param("startTime") String startTime, @Param("endTime") String endTime);

    @Select("SELECT\n" +
            "\tCOUNT( 1 ) \n" +
            "FROM\n" +
            "\tenterprise_improve \n" +
            "WHERE\n" +
            "\tenterprise_id = #{enterpriseId} \n" +
            "\tAND STATUS = 1 \n" +
            "\tAND deleted = 0")
    Integer selectAllEnterpriseImproveNum(@Param("enterpriseId") Long enterpriseId);
}
